using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using BUS;
using Utility;
using Encosia;
public partial class PH_KH_loaisp : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["Page"] = mainmenu.loaisp;
        if (!IsPostBack)
        {
            LoadData();
        }
    }

    private void LoadData()
    {
        try
        {
            int id=int.Parse(Request.QueryString["id"]);
            tbloaispDTO loaisp = tbloaisanphamBUS.GetByID(id);
            
            int total = 0;
            PagerV2_8_1.PageSize = 6;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbsanphamcolumn.Maloaisp.ToString(), Condition.EQUAL, int.Parse(Request.QueryString["id"]));

            rep_ChuDe.DataSource = tbsanphamBUS.GET(cri.Criter, PagerV2_8_1.CurrentIndex, PagerV2_8_1.PageSize,
            tbsanphamcolumn.Masp.ToString(), OrderDirection.ASC.ToString(), out total);
           
            rep_ChuDe.DataBind();
            PagerV2_8_1.ItemCount = total;
            if (total <= PagerV2_8_1.PageSize)
                PagerV2_8_1.Visible = false;
            else
                PagerV2_8_1.Visible = true;
        }
        catch
        {
            Response.Redirect("~PH_KH/loaisp.aspx");
        }
    }
    protected void rep_ChuDe_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
        e.Item.ItemType == ListItemType.Item)
        {
            tbsanphamDTO sanpham = (tbsanphamDTO)e.Item.DataItem;

            HyperLink lit_TenSp = (HyperLink)e.Item.FindControl("lit_TenSp");
            lit_TenSp.NavigateUrl = "chitietsp.aspx?id=" + sanpham.Masp.ToString();
            lit_TenSp.Text = sanpham.Tensp;
            Literal mota = (Literal)e.Item.FindControl("lit_mota");
            if (sanpham.Dacdiem.Length > 20)
                mota.Text = sanpham.Dacdiem.Substring(0, 50) + "...";
            else
                mota.Text = sanpham.Dacdiem;

            tbhinhanhDTOColection ha=tbhinhanhBUS.gethinh(sanpham.Masp);
            if (ha.Count < 0)
            {
                HighslideImage hinhanh = (HighslideImage)e.Item.FindControl("HighslideImage1");
                hinhanh.ImageUrl = "~/Admin/hinhanh/" + ha[0].Tenhinhanh.ToString();
                hinhanh.FullImageURL = "~/Admin/hinhanh/" + ha[0].Tenhinhanh.ToString();
            }
            else
            {
                HighslideImage hinhanh = (HighslideImage)e.Item.FindControl("HighslideImage1");
                hinhanh.ImageUrl = "~/Admin/hinhanh/" + ConfigurationManager.AppSettings["NoImage"];
                hinhanh.FullImageURL = "~/Admin/hinhanh/" + ConfigurationManager.AppSettings["NoImage"];
            }

          
        }

        
    }
}
